Custom Query
This activity performs a specified query in a database. See the tokens this activity produces.
How does this activity look in the Designer Pane?
- Drag it from the Toolbox Pane and drop it in the Designer Pane.
To configure this activity
Select the activity in the Designer Pane to configure the following property boxes in the Properties Pane.
See the following options:
-
Activity Name
Once added to a workflow definition, the default name of an activity can be changed. Providing a custom name for an activity helps you remember the role it plays.
To name an activity
- Add an activity to your workflow by dragging it from the Toolbox Pane and dropping it in the Designer Pane.
- Select the activity in the Designer Pane.
- Under Activity Name in the Properties Pane, replace the default name.
Note: Activity names cannot be the same as any other activity name in the workflow, they cannot be the same as the workflow's name, they must be less than 100 characters, they must contain at least one alphanumeric character, they cannot be "Name," and they cannot be the same as the activity's runtime type (which is usually only an issue with custom activities).
-
Activity Description
Use the Activity Description to provide descriptive text to help you remember the role that the activity plays in the workflow. All activities contain a default description that you can modify while constructing your workflow.
To modify an activity description
- Add an activity to your workflow by dragging it from the Toolbox Pane and dropping it in the Designer Pane.
- Select the activity in the Designer Pane.
- Under Activity Description in the Properties Pane, replace the default description.
-
Data Source
This property box determines which data source the activity will use.
To select a data source
- Add a Custom Query, Insert Data, Query Data, or Update Data activity to your workflow definition by dragging it from the Toolbox Pane and dropping it in the Designer Pane.
- Select the activity in the Designer Pane.
- Under Data Source in the Properties Pane, select a data source from the drop-down menu.
- Optional: To add, configure, remove, or test a connection to an external data source, select Manage Data Sources from the drop-down menu. More information.
- Optional: Click the refresh icon to update the list of data sources available in the drop-down menu.
Note: Because the Workflow Server performs the data-source queries, you must create all data sources on the Workflow Server. Services cannot access mapped drives when you are setting up the data source.
-
Custom Query
This property box allows you to insert a custom query to specify which table the Custom Query activity will search and which row's values it will return as tokens. This activity returns the values of the first row it finds as tokens. It also returns the collection of rows that have the specified column values.
Note: If this activity returns a collection of rows, you can access the tokens for each row with the For Each Row activity.
To configure Custom Query
- Add the Custom Query activity to your workflow definition by dragging it from the Toolbox Pane and dropping it in the Designer Pane.
- Select the activity in the Designer Pane.
- Under Custom Query in the Properties Pane, click in the box below Query to create a custom query.
- In the Custom Query Editor, enter your custom query under Custom Query.
- Optional: Type your Parameter Name under Parameter Names. How to specify the parameter names depends on how you are connecting to the data source:
- When using an ODBC connection, you cannot use named parameters. Use "?" for each parameter name. They are interpreted in the order in which they are listed. Show me what this looks like. You must list a parameter each time you use one in the query, even if you use the same parameter twice in the same query.
- To use named parameters, use an OLE DB connection. Named parameters can be used more than once in the query without being listed more than once in the parameter list. Show me what this looks like.
- Optional: Type your Parameter Value under Parameter Values, or click the Token button (right arrow) to use tokens.
- Optional: Choose a type for your parameter from the Type drop-down menu. You will want to set a parameter type if you are invoking a stored procedure that expects a specific type. Also, not all database drivers/servers automatically convert strings to the desired parameter type, so you might want to manually set the type in that situation. In most cases, you will want to leave the type as default. More info.
- When you enter a parameter name or value, an additional line appears for you type additional parameter names and values in. As you continue to type parameter names and values, additional lines appear.
- Optional: Remove a parameter name and value by clicking the red X .
- Click OK.
- Optional: To modify your query, click Edit in the Custom Query property box, or click anywhere in the Query or Parameters boxes. Repeat steps 4 through 9.
- Click the Test link to test your query.
- In the Define Query Parameters dialog box, insert the value you want to test.
- Click OK.
- The Test Query dialog box displays how many rows the query will return or any error (with accompanying error message) it encounters.
- Click OK.
Note: Different database sources have different syntaxes. The example below is written for the MSSQL ODBC. All queries are written in SQL. Use the correct syntax for your data source.
Tip: If you want a token to be replaced by the null value in the case that the token's value is blank (the empty string), apply the NULL token formatting expression. If you want to set a column's value to the null value regardless, insert the NULL token: %(DB.NULL).
Note: When using a SELECT query, you must test the query in order to make the columns accessible as tokens to the For Each Row activity.
-
Rows to Return
This property box determines how many rows the activity will return.
Note: If you chose to have these activities return more than one row, you can access the token values for the additional rows with the For Each Row activity.
To configure Rows to Return
- Add the Query Data or Custom Query activity to your workflow definition by dragging it from the Toolbox Pane and dropping it in the Designer Pane.
- Select the activity in the Designer Pane.
- Under Rows to Return in the Properties Pane, specify how many rows you want returned.
- First row only: Returns the first row in the database that contains the queried value. The database is searched from the top down.
- First ___ rows: Returns the first specified number of rows that contain the queried value. Type in the desired number of rows, or use the scroll box (up-and-down arrows) to select a number of rows. Alternatively, click the Token button (right arrow) to use tokens. The database is searched from the top down.
- All Rows: Returns all rows that contain the queried value.
-
Query Options
This property box allows you to specify a custom timeout for data query activities.
To specify a custom timeout
- Add a Custom Query, Insert Data, Query Data, or Update Data activity to your workflow definition by dragging it from the Toolbox Pane and dropping it in the Designer Pane.
- Select the activity in the Designer Pane.
- Under Query Options in the Properties Pane, select the Specify a custom timeout check box and specify the desired timeout value in seconds.
Note: The default timeout value is 30 seconds.
Note: When using a SELECT query, you must test the query in order to make the columns accessible as tokens to the For Each Row activity.